Hey there.
Welcome back.
In this next section of our project, we're going to start scripting one of the fundamental systems
for the game which are guns.
Now before we start scripting our guns I want to go ahead and walk through the different properties
I have in mind for each of our guns, to fully customize them in whatever way we want.
We're going to be able to customize the fire rate, how much ammo the guns have, how much damage they
deal, what the base damage should be, and how much we should multiply that damage based on what limb
a bullet hits, and so on.
So let's get started setting up the properties for our guns.
Our guns are currently stored in server storage.
If we go into the tools folder here, we have our different array of guns that we're going to be able
to customize and that players can purchase from our shop.
The first one we can go ahead and create a properties module script for will be like our pistol, because
this will be the basic first gun that most players will likely buy.
So we'll create a module script and we'll call it our properties.
And inside of here I'm going to define a table.
I'll just call it self and we'll make sure to return self at the end of our module script.
And inside of here is where we'll store all the properties for our guns.
I want to have a section relating to any damage properties, maybe a section to define the other miscellaneous
gun properties.
I want to have a section to store the different animations for our guns, as well as the sounds for
our guns and any other kind of miscellaneous properties.
So for the base damage of our gun, we could just create a property like damage.
And for my pistol, I want it to be relatively low.
So I could do a value of like 14.
And then next I want to define a table that defines how much we should multiply this base damage by
depending on what limb we hit on a character.
So we can call this our body part multipliers.
And we basically just want to have a key of all of the different names of the limbs and a player's character.
So if we go and we build an AR 15 rig.
And we go ahead and look inside of it.
There are a bunch of different limbs that are bullet can hit.
It can hit the upper torso or the lower torso.
It can hit the head, a foot, a hand, an arm, or even the humanoid root part.
So we want to be able to define how much we should multiply the base damage by like for example, if
we get a headshot.
So let's go ahead and create keys for each one of these limbs inside of our table.
We'll have one for the head, and by default I'm just going to set these values to one.
For now.
We'll have an upper torso.
We will have a lower torso.
We'll have a left foot, a right foot.
Will have a left lower leg as well as a right lower leg.
Will have a left upper leg and a right upper leg.
We'll have a left hand and a right hand.
We'll have a left lower arm.
A right lower arm will have a left upper arm.
A right upper arm.
And finally we'll have the humanoid root part.
Okay, so for our pistol, these are the values that we're going to multiply our base damage by for
when we get like a headshot or an upper torso shot or whatever.
So for the headshot, I'm thinking we should multiply the value by like four so they can deal more damage.
When they get a headshot for the upper torso, we can multiply it by a little bit more.
We could do like 1.2 for the upper torso, the lower torso, as well as the humanoid root part.
Because the humanoid root part is going to be encompassing both the upper torso and the lower torso
for the foot, we kind of want to deal like very little damage because we're hitting a foot.
So we could do like a value of 0.35 and do that for the other foot.
And we could do the same thing for the hands as well.
We don't want to deal a lot of damage when they hit those kind of limbs.
For the lower portion of the leg, we could do a little bit less damage, like 0.8.8.
And for the upper legs, we could do like 0.9, 0.9.
For the lower arm, we could do something like, I don't know, 0.6.
I'm just kind of throwing out numbers here.
We'll be able to experiment and adjust these values later.
And then for the upper arm we could do something like 0.7 and 0.7.
Okay.
Cool.
Now for the gun properties section.
We want to be able to define if this gun is going to be automatic or semi-automatic.
So I'll have a property, we'll call it automatic and our pistol is going to be semi-automatic.
So we'll set this value to false.
We can go ahead and define oops.
Let me go ahead and put a comma here.
We can go ahead and define the max distance that our bullet can travel.
So when we're raycasting we want to give a cap to how far that ray can reach.
So we'll call this our max bullet distance.
And we'll set it to a value of like 500 studs.
We can define how long it will take for us to reload our gun, how many seconds our reload duration
should be.
So we'll call it reload duration.
And for the pistol, I want it to be pretty short.
So we could do like two seconds.
The fire rate.
We can go ahead and define how many bullets we should be able to fire per minute.
So for the fire rate I'll do something like 300.
And then for the ammo, we want to define how much reserve ammo we can hold and how much ammo we can
hold inside of our magazine.
So we'll call this Max Reserve Ammo and we can set it to.
I want to have 12 bullets in the magazine, so we'll do 60 for the reserve ammo.
And then the Max mag ammo is going to be 12.
And then maybe we actually also want to add a section for defining the bullet holes.
So when our bullets hit something we want to put a bullet hole.
And we want to shoot particles out of the bullet hole just to make it look a little bit more realistic.
So we could define here what size the bullet hole should be.
So bullet hole size.
And if we actually go ahead and take a look in our game, if we go to, I believe, replicated storage,
we go to shared.
And I believe it's some parts.
Here we go.
We have our bullet hole right here.
Let me place this in the workspace and I'll find it right here.
So we want to be able to define what the size of this part should be depending on what it what gun fires,
what kind of bullet.
So if you had like a sniper rifle, of course you would want this bullet hole to be pretty large.
You would have a value of like, I don't know, one by one stud or something like that.
So it's a big fat bullet hole.
But if you had a pistol, like a low caliber pistol, then you would of course want the size to be much
smaller, maybe like 0.3.
And if you had a pellet from like a shotgun shooting birdshot, this would even be smaller.
You could have like a bullet hole that's only 0.1 by 0.1 studs.
So we really want to be able to customize what the size of our bullet hole should be, depending on
what gun is shooting the bullet.
So we place this back inside of replicated storage.
And we can head back into our module script.
And for the bullet hole size of our pistol, I want it to be slightly smaller than the 0.5 size.
So we could define a new vector three here.
And we'll make it point three by point three, and the thickness is going to be 001.
And then we can also define how many particles we would like to spit out of the bullet hole.
So if we have a big caliber bullet, we want to spit out more particles.
But if we have a small caliber bullet, we don't want to spit out that many particles.
So we could define the bullet whole particle amount, we'll call it.
And for my pistol, I'll just do four for now.
And let me place a comment here.
Now, the next section we can go ahead and define is going to be the animations.
So we can have a key.
We'll call it animations.
And inside of this table we could store the different animations for like equipping the gun, shooting
the gun, reloading the gun, stuff like that.
So we'll have an equip animation.
And inside of there we'll store an ID for that.
We'll have a reload animation and then we'll have a shoot animation.
We don't have the animations right now because we haven't made them, but once we create animations
for our guns, we'll go ahead and take those IDs and put them into their respective property.
Another thing we're going to want to define are the different sounds for our gun.
For example, what sound do we want to play when we shoot the gun?
So we could call this our shoot sound and it'll be our properties for the shoot sound.
So we can define the volume, the range, stuff like that.
We'll have it be a table.
We also want to define the sound for reloading the gun.
So we'll call this a reload sound properties.
And then I forgot to put a comma here.
So let me put that there.
And then we could also define um the sound we want to play when we're out of ammo.
So we'll play like a little click sound when we don't have any ammo left.
So we'll just call it gun click sound properties.
We also want to be able to add hit markers in the future for our guns.
So we may also want to define a sound for a hit marker, because when you play games, there's a little
sound that plays when you hit somebody with your bullets.
So we'll call it hit marker.
Sound properties.
Okay, last but not least, one more thing we can go ahead and define for our gun is going to be perhaps
configuring the muzzle flash that comes out of the barrel of our gun.
So if we have a big caliber gun, we want to have a big bright muzzle flash.
But if we have a small pistol, then we want the muzzle flash to be smaller.
So we can call this our muzzle flash properties.
And this property is going to be geared towards a point light that is inside of the muzzle.
So we want to manipulate the different properties in the point light such as the brightness.
What do we want to set the brightness to?
What do we want to set the color to?
Or what do we want to set the range of the light to stuff like that?
So since this is a gun, I want the brightness to be pretty bright.
We'll set it to a value of like five.
For the color.
We'll do a new color three from RGB and we'll pick kind of like I don't know, maybe a dark orangish
kind of color.
Let me see.
It'll be like a yellowish orange color.
We'll do something like that for now and then for the range.
Since this is a pistol, I don't want the range to be that big.
So we'll do something like five studs.
And then I also want to have shadows enabled for this point life.
So we'll set shadows equal to true okay.
Perfect.
So now what I'm going to do is I'm going to scour through the toolbox and look through different audio
files to try to find a good sound for shooting the pistol, reloading for the gun click, and for the
hit marker.
So I'll get back to you when I find any good sound IDs.
Okay, here I have found several good audios for shooting reloading the click sound and the hit marker
sound for our gun.
So let me go ahead and copy these IDs so you can go ahead and hear what it sounds like.
So this is going to be the shoot sound for our pistol I'll play it for you.
Very simple for the reload sound.
This is the sound that I've picked.
For the gun click sound.
We'll play this sound.
Very simple.
And then for the hit marker sound, we're going to be playing this sound.
And we can basically just use the exact same hit marker gun, click and reload sound across all of our
guns.
The main one you'll want to change is going to be the shoot sound for your gun.
Now we can go ahead and define some of the other properties we would like for our sound instance.
For example, we can go ahead and change the roll off mode and I'm going to set it equal to the enum
dot roll off mode of inverse tapered.
And I'm going to basically do that for all of my sounds because I like this mode the best.
So we'll do that.
We'll paste that paste that for each one of them.
The hit marker sound actually doesn't matter because we're going to play this on the client side.
So we don't need to play it in the workspace.
So I don't need to worry about a roll off mode or anything.
I think the only thing I'll need to worry about for the hit marker sound is going to be the volume,
but for the other guns, what we can go ahead and do is define some of the other properties, such as
the roll off max distance for the shoot sound.
I want that to be pretty far.
We could do something like 85 studs and then for the roll off min distance we could do something like
25 studs.
And for the volume I want to keep it at a volume of one.
So it's pretty loud for the shoot sound.
And then we can basically just copy this, go back in here and then just paste those properties inside
of these sounds.
So let me do this, paste that there for the reload sound.
I don't want it to be too loud and I don't want to hear it from too far away.
So we'll just do like 25 and 15 and the volume will make like 0.6.
And for the gun click sound again we'll do 2515.
And the click sound is actually pretty quiet.
So I want to bump up the volume a little bit.
I could do something like uh 1.5.
So now that we have the basic setup for the gun properties, we can just go ahead and copy this module
script and put it inside of all of our guns and just kind of manipulate or change these values for each
one of our guns.
So I'm going to do that for all of my guns real quick.
And if you would like to use the same properties that I'm going to be using, I'll have attached to
this lecture all of the different guns with the property module scripts attached to them, filled with
the different sound instances and the different properties for each one of the guns.
So I'll see you when I've copied all of these properties and adjusted them for each of the guns.
Okay, so I have gone through and adjusted all of the properties for each one of the guns in my game.
So for example, with my assault rifle, I've gone in here, adjusted the damage and the body part multipliers.
I've adjusted some of the gun properties, the bullet hole size, I've changed the shoot sound, and
I've also adjusted the muzzle flash properties a little bit.
Actually, let me make the range a little bit larger for the assault rifle.
So I've kind of changed around a couple of properties and then I've done the same for my SMG.
I've made it automatic, changed up the fire rate, stuff like that.
Now, however, I have done something a little bit different for the shotguns in my game.
So for example, this is the properties for my semi-automatic shotgun and I've added a few extra properties
just for the shotguns in our game.
If we scroll down, I've added these three properties to define the type of round for our shotgun,
how many pellets the shotgun should shoot out, and then what the spread should be for the shotgun.
So for example, if we have the string of the round type set to like buckshot or birdshot, then we're
going to use that to tell the script to spread the pellets outwards in a random manner, like a real
shotgun would shoot out pellets.
If we were to set the string to something like slug, then we're telling our script that we don't want
any spread whatsoever for our guns, because it's just going to be one big slug coming out of our shotgun.
But of course, we can still manipulate that based on the amount of pellets that are going to be coming
out of the shotgun.
So that's what we've done for the shotguns here.
And I've also gone ahead and added one additional sound properties for shotguns, and I've called it
shotgun pump Sound Properties.
And I put it in a sound ID here, and I basically want to play this sound during the reload animation,
where we'll play a pump sound like we're racking the shotgun.
So I've added that as well, and I believe that is all of the properties that I've added for my shotguns.
So I've added an additional sound as well as a couple or a few other shotgun properties.
So if I go ahead and take a look at, for example, my slug shotgun, I've set the round type to slug,
and I've defined that there should be only one pellet coming out of my slug shotgun.
And since slug shotguns will mess you up, I've increased the damage a lot and increased the multipliers,
especially for like, headshots.
I also have this other little fun gun here, I think.
I'm not sure what I'm going to do with this gun, but it's just going to be like a little fun testing
gun where it has just some absolutely insane properties, a crazy amount of ammo, a high fire rate,
and it does crazy damage.
So this is going to be kind of like a fun little experiment gun that we're going to use later when we're
done scripting our guns.
But now we have all the respective properties set up for every single gun in our game.
All of these guns with their properties have been attached to the lecture for you to use if you would
like to use them.
And other than that, we're now ready to start scripting the guns for our game.
So that includes scripting the muzzle flash, shooting out array and seeing if we hit anything.
Being able to reload our guns and display how much ammo we have with these guys that are inside of our
guns.
So let's actually take a look at one of these guys.
I'll change the parent of this guy to my starter guy service.
So we'll go down, place it in there and then let me enable UI visibility.
So here is our simple gun guy.
It'll just say the name of the gun.
And then we have a couple of text labels here to tell us how much magazine ammo we have left and then
how much reserve ammo we have left.
And then we also have an image of a hit marker.
And we're going to be moving this hit marker around when we hit something with our gun, and we'll just
place the hit marker around our mouse icon.
So it looks like, you know, we shot something.
So let me go ahead and move this guy back inside of its gun.
So let me go back to server storage and put it back in my assault rifle.
And other than that, we are ready to start scripting our guns.
So I'll see you in the next lecture.